package com.zyd.blog.homeart.service.impl;

import com.zyd.blog.framework.object.PageResult;
import com.zyd.blog.homeart.service.BackstageReportTypeService;
import com.zyd.blog.persistence.beans.ReportType;
import com.zyd.blog.persistence.mapper.ReportTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class BackstageReportTypeServiceImpl implements BackstageReportTypeService {

    @Autowired
    private ReportTypeMapper reportTypeMapper;

    @Override
    public PageResult listAll(int page, int count) {
        PageResult pageResult = new PageResult();
        Map<String,Object> map = new HashMap<>();
         map.put("page",page);
        ReportType reportType = new ReportType();
        reportType.setState("0");
        int i = reportTypeMapper.selectCount(reportType);
        if (i%count==0){
            map.put("allPage",i/count);
        }else {
            map.put("allPage",i/count+1);
        }
        map.put("list",reportTypeMapper.listAll(page*count-count,count));
        pageResult.setTotal((long)i);
        pageResult.setRows(reportTypeMapper.listAll(page*count-count,count));
        return pageResult;
    }

    @Override
    public Integer updateReportType(String id,String content) {
        return reportTypeMapper.updateReportType(id,content);
    }

    @Override
    public Integer deleteReportType(int id) {
        return reportTypeMapper.deleteRe(String.valueOf(id));
    }

    @Override
    public ReportType get(String id) {
       return reportTypeMapper.get(id);
    }

    @Override
    public Integer addReportType(String content) {
        ReportType reportType = new ReportType();
        reportType.setContent(content);
        reportType.setState("0");
        return reportTypeMapper.insert(reportType);
    }
}
